package exception;

/**
 * Java异常处理机制：try...catch
 * try{
 *     代码片段
 * }catch(xxxException e){
 *     当try的代码片段出现xxxException时的补救措施
 * }
 */
public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了");
        try{
            String line = null;
            System.out.println(line.length());
            line = "";
            line.charAt(0);
            return;
        }catch (NullPointerException e){
            System.out.println("出现了空指针异常并解决了");
        }catch (StringIndexOutOfBoundsException e){
            System.out.println("下标越界异常");
        }catch (Exception e){
            System.out.println("反正就是出现异常了");
        }finally {
            System.out.println("不论如何都会执行的代码");
        }
        System.out.println("程序结束了");
    }
}
